package cn.org.timespace.ons.inside.webservice.client;

import java.net.MalformedURLException;
import java.net.URL;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.codehaus.xfire.client.Client;

import cn.org.timespace.ons.inside.common.SocketInPropertie;



public class WebServiceClient {

	public static String client = SocketInPropertie.getProperty("webservice.client.link", "localhost");
	public static final String methodsName = SocketInPropertie.getProperty("webservice.client.methodsName");
	
//	public Object[] SendMessage(Object[] obj) throws MalformedURLException, Exception{
//		Client cl = new Client(new URL(client));
//		Object[] resutls = cl.invoke(methodsName, obj);
//		return resutls;
//	}
	
	public WebServiceClient(){}
	
	public WebServiceClient(String ip,String port){
		client = client.replaceAll("webserviceIP", ip);
		client = client.replaceAll("webservicePORT", port);
	}
	
	public String sendMessage(Object[] obj) throws MalformedURLException, Exception{
		String result="1";
		try {
//			http://192.168.2.27:88/Work/services/SmsWebService?wsdl
			
//			Service service = new Service();
//			Call call = null;
//			call = (Call) service.createCall();
//			call.setTargetEndpointAddress(new java.net.URL("http://192.168.2.27:88/Work/services/SmsWebService?wsdl"));
//			call.setOperationName(methodsName);
//			call.setReturnType(call.getReturnType());
//			result=(String)call.invoke(obj);
//			System.out.print(result);
			
			Client ct = new Client(new URL(client)); // 根据WSDL创建客户实例
			Object[] results = ct.invoke(methodsName,obj);
			result = results[0].toString();
			System.out.println(results[0]);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
		}
		return result;
	}
	
}